package com.zou.server.service.impl;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zou.model.entity.User;
import com.zou.model.mapper.UserMapper;
import com.zou.server.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/*
 * @auth zoujt
 * @date 2021/3/17
 * @Description
 */
@Service
public class UserServiceIml extends ServiceImpl<UserMapper,User> implements UserService {
    @Resource
    private UserMapper userMapper;

   /**
    *
    * @Methods: 查询所有
    * @author zoujt
    * @creed: Talk is cheap,show me the code
    * @date 2021/3/17
    */
    @Override
    public List<User> findAll() {

//        int i = 1/0;
        return userMapper.findAll();

    }

    /**
     *
     * @Methods: 添加用户
     * @author zoujt
     * @creed: Talk is cheap,show me the code
     * @date 2021/3/17
     */

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int addUser(User user) {
//        int i = 1/0;
        int result = userMapper.addUser(user);
        return result;
    }

    /**
     *
     * @Methods: 根据id删除
     * @author zoujt
     * @creed: Talk is cheap,show me the code
     * @date 2021/3/17
     */

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int delete(Long id) {
//        int i = 1/0;
        int result = userMapper.delete(id);
        return result;
    }

    /**
     *
     * @Methods: 修改用户
     * @author zoujt
     * @creed: Talk is cheap,show me the code
     * @date 2021/3/17
     */

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update(User user) {
//        int i = 1/0;
        int result = userMapper.update(user);
        return result;
    }

    /**
     *
     * @Methods: 根据id查询
     * @author zoujt
     * @creed: Talk is cheap,show me the code
     * @date 2021/3/17
     */

    @Override
    public User findById(Long id) {
        User user = userMapper.findById(id);
        return user;
    }


    //mybatis-plus
    public List<User> listAll(){
        List<User> list = this.list();
        return list;
    }

    public User getOne1(Long id){
        User user = this.getById(id);
        return user;
    }

}
